// 用户相关的数据存这里 token
export default {
  namespaced: true,

  state: () => {
    const cachedUserinfo = uni.getStorageSync('userinfo')

    return {
      // 登录后的 token 字符串
      token: uni.getStorageSync('token') || '',
      userinfo: cachedUserinfo ? JSON.parse(cachedUserinfo) : {},
    }
  },

  getters: {},

  mutations: {
    setToken(state, token) {
      state.token = token || ''

      uni.setStorageSync('token', state.token)
    },
    // 更新用户的基本信息
    updateUserInfo(state, userinfo) {
      state.userinfo = userinfo

      // 持久化到本地缓存
      uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
    },
  },

  actions: {},
}
